package com.psp.bu.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.psp.bu.controller.res.*;
import com.psp.bu.controller.res.bean.*;
import com.psp.bu.controller.springmvc.req.*;

/**
 * 服务商-相关接口
 **/
@Controller
@RequestMapping(value = "/bu/sp", produces = "application/json")
public class SSPController {
	@Autowired
	com.psp.bu.controller.SPController sPController;

	/**
	 * 获取全部消息
	 **/
	@RequestMapping("/v1/detail")
	@ResponseBody
	public ObjectResult<RSPDetailBean> detail(@Validated GetSPDetailParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RSPDetailBean> res = new ObjectResult<RSPDetailBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return sPController.detail(param, request, response);
	}

	/**
	 * 获取全部消息
	 **/
	@RequestMapping("/v1/joined")
	@ResponseBody
	public ListResult<RJoinedSPBean> joined(@Validated GetJoinedSPParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RJoinedSPBean> res = new ListResult<RJoinedSPBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return sPController.joined(param, request, response);
	}

	/**
	 * 获取申请的服务商
	 **/
	@RequestMapping("/v1/getApply")
	@ResponseBody
	public ListResult<RApplySPListBean> getApply(@Validated GetApplySPListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RApplySPListBean> res = new ListResult<RApplySPListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return sPController.getApply(param, request, response);
	}

	/**
	 * 同意服务商的申请
	 **/
	@RequestMapping("/v1/agreeJoin")
	@ResponseBody
	public BaseResult agreeJoin(@Validated GetAgreeJoinParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return sPController.agreeJoin(param, request, response);
	}

	/**
	 * 驳回服务商的申请
	 **/
	@RequestMapping("/v1/disagreeJoin")
	@ResponseBody
	public BaseResult disagreeJoin(@Validated GetDisagreeJoinParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return sPController.disagreeJoin(param, request, response);
	}

	/**
	 * 服务商订单列表
	 **/
	@RequestMapping("/v1/orders")
	@ResponseBody
	public ListResult<RSPOrderListBean> orders(@Validated GetSPOrderListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RSPOrderListBean> res = new ListResult<RSPOrderListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return sPController.orders(param, request, response);
	}

	/**
	 * 服务商评价列表
	 **/
	@RequestMapping("/v1/comments")
	@ResponseBody
	public ListResult<RSPCommentListBean> comments(@Validated GetSPCommentListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RSPCommentListBean> res = new ListResult<RSPCommentListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return sPController.comments(param, request, response);
	}
}
